// pages/creat/creat.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentQuestion: 10
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight,
          userInfo: wx.getStorageSync('userInfo')
        })
      }
    })
  },
  sliderchange: function (e) {
    this.setData({
      currentQuestion: parseInt(e.detail.value) + parseInt(5),
    })
  },
  startQuestion: function () {
    var that = this;
    wx.request({
      url: app.globalData.allUrl + "/api/find_question.php",
      data: {
        number: that.data.currentQuestion,
      },
      header: { 'content-type': "application/x-www-form-urlencoded" },
      method: 'POST',
      success: function (res) {
        console.log(res.data)
        if(res.data.data.length>4){
          app.globalData.userCurrentQuestions = res.data.data;
          wx.setStorageSync("userCurrentQuestions", res.data.data)
          console.log(wx.getStorageSync("userCurrentQuestions").length)
          wx.redirectTo({
            url: '../../pages/question/question',
          })
        }
      }, fail: function () {
         wx.showModal({
           title: '提示',
           content: '获取考题失败！',
         })
      }
    })
  }
})